home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / ratbas.arc / RATBAS.UM < prev    next >
Encoding:
Text File  |  1982-08-10  |  9.6 KB  |  349 lines

  1.                THE RATBAS LANGUAGE
  2.  
  3. RATBAS (rhymes with "fat case") stands for "Rational Basic". It is a 
  4. language designed to provide some of the advantages of structured 
  5. languages (e.g. Pascal) but to allow simple and rapid translation to 
  6. Microsoft BASIC for the IBM Personal Computer. 
  7.  
  8. A RatBas program consists of lines written in standard BASIC and lines
  9. using features unique to RatBas. The latter are "flagged" for the
  10. translator by a right bracket (]) at the end of the line. Lines not
  11. ending with a right bracket are inserted in the BASIC program with
  12. no change except the possible addition of a line number.
  13.  
  14. To translate a RATBAS program to an equivalent BASIC program, simply 
  15. "run it through" program RT. 
  16.  
  17. For example:
  18.  
  19.       A> RT
  20.          RatBas Program?  zilch;
  21.  
  22. This will produce a basic program under the name ZILCH.BAS. For 
  23. further information, see the entry under RT in the User's Manual. 
  24.  
  25. The rules for RATBAS are relatively simple.
  26.  
  27. No line numbers are required (or allowed). RT will provide them as 
  28. needed. 
  29.  
  30. Upper or lower case characters are allowed. Blank lines may be included.
  31.  
  32. The initial portion of the program should consist of declarations 
  33. and/or dimension statements. No executable statement should be 
  34. included. 
  35.  
  36. The next portion should consist of PROCEDURES. These are equivalent to 
  37. BASIC subroutines but have names. A procedure is declared in the 
  38. following manner: 
  39.  
  40.        PROCEDURE procedure-name]
  41.  
  42. For example:
  43.  
  44.        PROCEDURE GetFile]
  45.  
  46. In all such statements, the right bracket must be the last character 
  47. in the (logical) line. 
  48.  
  49. The end of a procedure is identified by:
  50.  
  51.      PEND]
  52.  
  53. To invoke a procedure, simply give its name, followed by a right 
  54. bracket at the end of a line. For example: 
  55.  
  56.      GetFile]
  57.  
  58.      If not done then GetFile]
  59.  
  60. Upper and lower case may be used in procedure names (the translator
  61. considers all characters in a procedure name to be upper case whether
  62. they are or not).
  63.  
  64. A procedure reference (call) can appear at the end of any BASIC statement
  65. as long as GOSUB ---  would be legal in the position.
  66.  
  67. A procedure may call another procedure but the called procedure must
  68. precede the one calling it in the program file.
  69.  
  70. The name ERROR is reserved. If a procedure named ERROR is included in
  71. a RatBas program, it will be invoked automatically in the event of an
  72. error when the BASIC program is run. After code in the  ERROR procedure
  73. has been executed, the BASIC program will resume at the statement
  74. following the one causing the error condition.
  75.  
  76. After all procedures have been declared, the file should have a line
  77. declaring the program:
  78.  
  79.      PROGRAM]
  80.  
  81. Following this come the statements for the main program, including any
  82. statements that call procedures.
  83.  
  84. In a procedure or the main program one may use RATBAS "if blocks"
  85. of the form:
  86.  
  87.       If -------  then]
  88.         .
  89.         .
  90.       Ifend!
  91.  
  92.   or:
  93.  
  94.  
  95.         If ---------- then] 
  96.              .
  97.              .
  98.            else] 
  99.              . 
  100.              . 
  101.          ifend] 
  102.  
  103. Note that "ifend" must be written as one word. The material between IF] 
  104. and THEN] can be any legal BASIC construct. 
  105.  
  106. Two pre-declared values are TRUE and FALSE. They may be used in 
  107. comparisons or for assignments. For example: 
  108.  
  109.     if (a>b) then notdone=true
  110.  
  111. All variables beginning with i,j,k,l,m or n will be considered 
  112. integers. This may be changed on a variable-by-variable basis by using 
  113. extended variable names (e.g. $, etc.) Alternatively, a DEF-  
  114. statement may be included to override the default. 
  115.  
  116. The BASIC program produced by RT will contain the procedures with line 
  117. numbers that are even multiples of 100. A list of procedures, with 
  118. their line numbers, will begin at line number 20000. 
  119.  
  120. RatBas programs may also include CASE statements of the form:
  121.  
  122.          CASE <lhs> of]
  123.              <rhs1> :]
  124.                       <statements-1>
  125.              <rhs2> :]
  126.                       <statements-2>
  127.              OTHERWISE]
  128.                       <statements-3>
  129.           CEND]
  130.  
  131. <lhs> can be any statement that is legal in an IF statement; as can 
  132. <rhs>. The effect of this structure is as follows: 
  133.  
  134.         IF <lhs>=<rhs1> then <statements-1>
  135.         IF <lhs>=<rhs2> then <statements-2>
  136.         Otherwise   <statements-3>
  137.  
  138. If OTHERWISE] is omitted, the translator will insert an OTHERWISE 
  139. section with no executable statements. 
  140.  
  141. Note that in a CASE statement, alternative selections are evaluated in 
  142. order. For efficiency, the more likely alternatives should be placed 
  143. first. 
  144.  
  145. Procedures may include arguments. Their use can be best described
  146. by example:
  147.  
  148.       PROCEDURE Sum (x,y,v:z)]
  149.             z=x+y
  150.       PEND]
  151.         .
  152.         .
  153.         .
  154.       PROGRAM]
  155.         .
  156.        SUM (a, b+3, c)
  157.         .
  158.  
  159. In the procedure declaration, only unsubscripted variable names may be 
  160. given. These are global (in the sense that they are the same as other 
  161. variables in the program). The effect of the foregoing is to produce a 
  162. basic program withe following statements for the "call": 
  163.  
  164.      x=a
  165.      y=b+3
  166.      z=c
  167.      GOSUB ..... ' SUM
  168.      c=z
  169.  
  170. Note that only the third argument is re-assigned when the procedure  
  171. (subroutine) is completed (since it is declared "variable" in the 
  172. procedure) . Expressions may be used in a procedure call for any 
  173. argument not declared variable. 
  174.  
  175. Program RT allows the use of INCLUDE files. One need only include a 
  176. line of the form: 
  177.  
  178.        INCLUDE Zilch]
  179.  
  180. to indicate that the named file is to be inserted at this point as if 
  181. it had been part of the RatBAS program. If no disk drive is given, the 
  182. default disk is assumed; if no extension is given, .INC is assumed. 
  183.  
  184. The following program demonstrates the use of most of the features of 
  185. RATBAS. It is designed to read a file in the DIF format (produced by 
  186. VisiCalc programs) and make a copy in the same format. 
  187.  
  188.  -------------------------------------------------------------------
  189.  
  190. 'Include file RWDIF.INC
  191. 'routines to read and write DIF files
  192.  
  193. 'CONSTANTS
  194.     quote$=chr$(34)
  195.     nul$=chr$(34)+chr$(34)
  196.     
  197. PROCEDURE WriteHeader(numvecs,numtups)]
  198. 'writes header for DIF file (#2)
  199.     'write standard table header
  200.     print #2, "TABLE"
  201.     print #2,"0,1"
  202.     print #2,nul$
  203.     'write number of vectors
  204.     print #2,"VECTORS"
  205.     print #2,"0,";numvecs
  206.     print #2,nul$
  207.     'write number of tuples
  208.     print #2,"TUPLES"
  209.     print #2,"0,";numtups
  210.     print #2,nul$
  211.     'write standard data header
  212.     print #2,"DATA"
  213.     print #2,"0,0"
  214.     print #2,nul$
  215. PEND]
  216.  
  217. PROCEDURE WriteBOT]
  218. 'writes beginning-of-tuple header
  219.     print #2,"-1,0"
  220.     print #2,"BOT"
  221. PEND]
  222.  
  223. PROCEDURE WriteEOD]
  224. 'writes an end-of-data record
  225.     print #2,"-1,0"
  226.     print #2,"EOD"
  227. PEND]
  228.  
  229. PROCEDURE WriteValue]
  230. 'writes VALUE
  231.     print #2,"0,";value
  232.     print #2,"V"
  233. PEND]
  234.  
  235. PROCEDURE WriteString]
  236. 'writes STG$
  237.     print #2,"1,0"
  238.     print #2,quote$;stg$;quote$
  239. PEND]
  240.  
  241. PROCEDURE ReadTriplet]
  242. 'reads title$,ntype,number,string$
  243.     input #1,title$
  244.     input #1,ntype,number
  245.     input #1,stg$
  246. PEND]
  247.  
  248. PROCEDURE ReadHeader(v:numvecs,v:numtups,v:ok)]
  249. 'reads header and gets number of vectors and tuples
  250. 'ok=true if a DIF file, false if not
  251.     'set ok=false until all set
  252.     ok=false
  253.     'header
  254.     ReadTriplet]
  255.     if title$<>"TABLE" then return
  256.     'vectors
  257.     ReadTriplet]
  258.     if title$<>"VECTORS" then return
  259.     numvecs=number
  260.     'tuples
  261.     ReadTriplet]
  262.     if title$<>"TUPLES" then return
  263.     numtups=number
  264.     'data header
  265.     ReadTriplet]
  266.     if title$<>"DATA" then return
  267.     'if made it to here, file is OK
  268.     ok=true
  269. PEND]
  270.  
  271. PROCEDURE ReadPair]
  272. ' reads ntype, value, stg$
  273.     input #1, ntype, value
  274.     input #1, stg$
  275. PEND]
  276.  
  277. PROCEDURE ReadNextCell]
  278. 'reads next cell
  279. ' sets type$ = "a"or "r" 
  280. '    if "a", stg$ is string
  281. '    if "r", val is real value
  282.     'read pair
  283.     ReadPair]
  284.     case ntype of]
  285.         0 :]
  286.            type$="r"
  287.         1 :]
  288.            type$="a"
  289.         cend]
  290. PEND]
  291.  
  292. PROGRAM]
  293.     'reads one dif file and makes a copy
  294.     input "source file: ",file1name$
  295.     open file1name$ for input as #1
  296.     input "destination file: ",file2name$
  297.     open file2name$ for output as #2
  298.     'headers
  299.     ReadHeader]
  300.         print numvecs;" Vectors,    ";numtups;" Tuples"
  301.     WriteHeader]
  302.     'tuples
  303.     for i=1 to numtups
  304.     ' BOT
  305.         readpair]
  306.         writeBOT]
  307.     'entries
  308.         for j=1 to numvecs
  309.         ReadNextCell]
  310.             case type$ of]
  311.             "r" :]
  312.                  WriteValue]
  313.             "a" :]
  314.                  WriteString]
  315.                 cend]
  316.         next j
  317.     next i
  318.     'end-of-data
  319.     WriteEOD]
  320. END
  321.  
  322.  --------------------------------------------------------------------
  323.  
  324.  
  325. Since BASIC has neither local variables nor true arguments for 
  326. multi-line procedures, some care is needed if programs are to be 
  327. written in a truly modular fashion. One helpful procedure is to name 
  328. all "local" variables in a procedure with the name of the procedure. 
  329. Thus in procedure Zilch: 
  330.  
  331.       i.zilch
  332.       x.zilch
  333.   
  334.      etc.. 
  335.  
  336. If names with decimal points are used only in this way, few if any 
  337. conflicts should arise. 
  338.  
  339. As a practical matter, one may draft a program in RATBAS, then 
  340. translate it to BASIC for use with the interpreter. A printed copy of 
  341. the RATBAS program should be made for posting changes. Then the BASIC 
  342. program should be debugged, with changes posted to the printed version 
  343. of the RATBAS program. When the BASIC program is working, the RATBAS 
  344. version should be modified as apropriate. Then RT should be used to 
  345. produce a version with no unnecessary line numbers (using the "/N" 
  346. option). The latter can then be compiled with the BASIC compiler 
  347. (using the "/N" option) to produce efficient compiled code. 
  348.  
  349.